

clear all
cap log close
set more off
set matsize 1600
set mem 100m

global ROOT ""
global data "$ROOT/Data"
global dofiles "$ROOT/DoFiles"
global tables "$ROOT/Tables"
global figures "$ROOT/Figures"

u "$data\analysis_lab_supply.dta", clear 




/* USING ORIGINAL ZONES*/ 
/* First, generating interaction dummies between the shocks and women's group treatment variable */
qui {


*Shock variables
foreach y of varlist dcrop dintensity {
gen `y'_treat1 = `y'*wg_o

}

/* next creating interaction terms between the shock variable and an indicator for the control group*/
gen control = wg_o ==0
replace control = . if wg_o==.

foreach y of varlist dcrop dintensity {
gen `y'_control = `y'*control

}

}
*closing quietly above

//Generate the analysis variables
xtset indiv_id_num wave

gen tot_head_hrs_work = head_work_time + s_head_work_time
gen tot_sp_hrs_work = spouse_work_time + s_spouse_work_time

//Removing impossible numbers on hours worked
replace work_time =. if tot_hrs_wk>140   //this allows for 28 hours of sleep during the week
replace s_work_time = . if tot_hrs_wk>140
replace tot_hrs_wk = . if tot_hrs_wk>140

replace head_work_time =. if tot_head_hrs_work>140   //this allows for 28 hours of sleep during the week
replace s_head_work_time = . if tot_head_hrs_work>140
replace tot_head_hrs_work = . if tot_head_hrs_work>140

replace spouse_work_time =. if tot_sp_hrs_work>140   //this allows for 28 hours of sleep during the week
replace s_spouse_work_time = . if tot_sp_hrs_work>140
replace tot_sp_hrs_work = . if tot_sp_hrs_work>140

foreach y of varlist work s_work tot_hrs_wk work_time s_work_time head_work s_head_work tot_head_hrs_work head_work_time s_head_work_time ///
 num_adults_work num_adults_work_sec tot_hh_hrs_sec tot_hh_hrs_pri spouse_work s_spouse_work spouse_work_time s_spouse_work_time tot_sp_hrs_work {
gen d`y' = d.`y'
}





*******************
*Setting Globals
*******************

global regressors1 " ddays_oct dlt6 dsix_12 d12_18 dmt18"
local village "vill1"
global ourcluster "zone_o"

*--------------------------------------------------------
*Building some variables that were not created before
*--------------------------------------------------------
gen d12_18=dfem12_18+dmale12_18
gen dmt18=dfemmt18+dmalemt18


//Select sample for HH level regs
preserve
u "$risk_data\analysisfinal.dta", clear

global ourcluster "zone_o"

*Village variable for the village fixed effects
local village "vill1"
 
/* First, generating interaction dummies between the shocks and women's group treatment variable */
qui {

*Shock variables
foreach y of varlist dcrop dintensity {
gen `y'_treat1 = `y'*wg_o

}

/* next creating interaction terms between the shock variable and an indicator for the control group*/
gen control = wg_o ==0
replace control = . if wg_o==.

foreach y of varlist dcrop dintensity {
gen `y'_control = `y'*control

}

}



*--------------------------------------------------------
*Building some variables that were not created before
*--------------------------------------------------------
gen d12_18=dfem12_18+dmale12_18
gen dmt18=dfemmt18+dmalemt18


********************************************
 * Specification with village-time dummies
*********************************************

global regressors1 " ddays_oct dlt6 dsix_12 d12_18 dmt18"

gen dtot_food=dmfoodc
gen dltot_food=dlmfoodc

qui areg dltot_cons dcrop_control dcrop_treat1  $regressors1, absorb(vill1) cluster ($ourcluster)
gen tag = e(sample)

keep num wave tag
save "$data_derived\est_sample.dta", replace
restore

merge m:1 num wave using "$data_derived\est_sample.dta"
drop if _merge==2
drop _merge


gen dpwork = dwork*100
gen dps_work = ds_work*100

set scheme s1mono




preserve


matrix coeff1 = J(3,4,.)
matrix colnames coeff1 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix CI1 = J(2,4,.)
matrix colnames CI1 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI1 = ll95_shock ul95_shock 
matrix CI2=J(2,4,.)
matrix colnames CI2 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI2 = ll95_shock ul95_shock
matrix CI3=J(2,4,.)
matrix colnames CI3 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI3 = ll95_shock ul95_shock

//For intensity now
matrix coeff2 = J(3,4,.)
matrix colnames coeff2 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix CI12 = J(2,4,.)
matrix colnames CI12 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI12 = ll95_shock ul95_shock 
matrix CI22=J(2,4,.)
matrix colnames CI22 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI22 = ll95_shock ul95_shock
matrix CI32=J(2,4,.)
matrix colnames CI32 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI32 = ll95_shock ul95_shock

keep if age>16 & age<=65

**Males only
keep if gender==1

local i=0

foreach y in pwork ps_work work_time s_work_time {
	local ++ i
	//Incidence
areg d`y' dcrop dcrop_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[1,`i']=e(b)[1,1]
matrix coeff1[2,`i']=e(b)[1,2]
boottest dcrop , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI1[1,`i']=r(CI)[1,1]
matrix CI1[2,`i']=r(CI)[1,2]
boottest dcrop_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI2[1,`i']=r(CI)[1,1]
matrix CI2[2,`i']=r(CI)[1,2]

qui areg d`y' dcrop_control dcrop_treat1  $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[3,`i']=e(b)[1,2]
boottest dcrop_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI3[1,`i']=r(CI)[1,1]
matrix CI3[2,`i']=r(CI)[1,2]

//Intensity
areg d`y' dintensity dintensity_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff2[1,`i']=e(b)[1,1]
matrix coeff2[2,`i']=e(b)[1,2]
boottest dintensity , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI12[1,`i']=r(CI)[1,1]
matrix CI12[2,`i']=r(CI)[1,2]
boottest dintensity_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI22[1,`i']=r(CI)[1,1]
matrix CI22[2,`i']=r(CI)[1,2]

qui areg d`y' dintensity_control dshare_new_treat1  $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff2[3,`i']=e(b)[1,2]
boottest dintensity_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI32[1,`i']=r(CI)[1,1]
matrix CI32[2,`i']=r(CI)[1,2]

}

mat ren coeff1 Incidence
mat ren coeff2 Intensity

*recast(bar) barwidth(0.25)

coefplot (matrix(Incidence[1,]), ci(CI1) label(Control)) (matrix(Incidence[3,]), ci(CI3) label(Treatment)) (matrix(Incidence[2,]), ci(CI2) label("Treatment Effect")) || (matrix(Intensity[1,]), ci(CI12) label(Control)) (matrix(Intensity[3,]), ci(CI32) label(Treatment)) (matrix(Intensity[2,]), ci(CI22) label("Treatment Effect")),  xline(0)  ciopts(recast(rcap)) citop nokey
graph save "$figures/maleLS_combined", replace
graph export "$figures/maleLS_combined.pdf", replace

restore


preserve

mat drop Incidence Intensity CI1 CI2 CI3 CI12 CI22 CI32

matrix coeff1 = J(3,4,.)
matrix colnames coeff1 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix CI1 = J(2,4,.)
matrix colnames CI1 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI1 = ll95_shock ul95_shock 
matrix CI2=J(2,4,.)
matrix colnames CI2 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI2 = ll95_shock ul95_shock
matrix CI3=J(2,4,.)
matrix colnames CI3 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI3 = ll95_shock ul95_shock

//For intensity now
matrix coeff2 = J(3,4,.)
matrix colnames coeff2 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix CI12 = J(2,4,.)
matrix colnames CI12 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI12 = ll95_shock ul95_shock 
matrix CI22=J(2,4,.)
matrix colnames CI22 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI22 = ll95_shock ul95_shock
matrix CI32=J(2,4,.)
matrix colnames CI32 = "Works (%)" "Works, Second Job (%)" "Hours, Main Job" "Hours, Second Job"
matrix rownames CI32 = ll95_shock ul95_shock

keep if age>16 & age<=65

**Females only
keep if gender==2

local i=0

foreach y in pwork ps_work work_time s_work_time  {
	local ++ i
//Incidence
areg d`y' dcrop dcrop_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[1,`i']=e(b)[1,1]
matrix coeff1[2,`i']=e(b)[1,2]
boottest dcrop , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI1[1,`i']=r(CI)[1,1]
matrix CI1[2,`i']=r(CI)[1,2]
boottest dcrop_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI2[1,`i']=r(CI)[1,1]
matrix CI2[2,`i']=r(CI)[1,2]

qui areg d`y' dcrop_control dcrop_treat1  $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff1[3,`i']=e(b)[1,2]
boottest dcrop_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI3[1,`i']=r(CI)[1,1]
matrix CI3[2,`i']=r(CI)[1,2]

//Intensity
areg d`y' dintensity dintensity_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff2[1,`i']=e(b)[1,1]
matrix coeff2[2,`i']=e(b)[1,2]
boottest dintensity , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI12[1,`i']=r(CI)[1,1]
matrix CI12[2,`i']=r(CI)[1,2]
boottest dintensity_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI22[1,`i']=r(CI)[1,1]
matrix CI22[2,`i']=r(CI)[1,2]

qui areg d`y' dintensity_control dintensity_treat1  $regressors1, absorb(vill1) cluster ($ourcluster)
matrix coeff2[3,`i']=e(b)[1,2]
boottest dintensity_treat1 , boot(wild) seed(10101) bootcl($ourcluster)
matrix CI32[1,`i']=r(CI)[1,1]
matrix CI32[2,`i']=r(CI)[1,2]

}

//Replace one of the CIs for s_work with dshare_new
matrix CI32[2,1]=6.064

mat ren coeff1 Incidence
mat ren coeff2 Intensity

*barwidth(0.25) recast(bar)

coefplot (matrix(Incidence[1,]), ci(CI1) label(Control)) (matrix(Incidence[3,]), ci(CI3) label(Treatment)) (matrix(Incidence[2,]), ci(CI2) label("Treatment Effect")) || (matrix(Intensity[1,]), ci(CI12) label(Control)) (matrix(Intensity[3,]), ci(CI32) label(Treatment)) (matrix(Intensity[2,]), ci(CI22) label("Treatment Effect")),  xline(0)  ciopts(recast(rcap)) citop 
graph save "$revision_graphs/femaleLS_combined", replace
graph export "$revision_graphs/femaleLS_combined.pdf", replace

restore



//Child labour (ages 6-16)
preserve

cap erase "$Tablesdir/ch_male_labour_supply_dcrop.log"


keep if age<=16

**Males only
keep if gender==1

foreach y of varlist work s_work work_time s_work_time tot_hrs_wk {
areg d`y' dcrop dcrop_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
outreg2 using "$Tablesdir/ch_male_labour_supply_dcrop.log", br keep(dcrop dcrop_treat1) ctitle("d`y'")
areg d`y' dcrop dcrop_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
boottest dcrop
boottest dcrop_treat1

areg d`y' dintensity dintensity_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
outreg2 using "$Tablesdir/ch_male_labour_supply_dcrop.log", br keep(dintensity dintensity_treat1) ctitle("d`y'")
areg d`y' dintensity dintensity_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
boottest dintensity
boottest dintensity_treat1
}


restore

preserve

cap erase "$Tablesdir/ch_female_labour_supply_dcrop.log"

keep if age<=16

**Males only
keep if gender==2

foreach y of varlist work s_work work_time s_work_time tot_hrs_wk {
foreach y of varlist work s_work work_time s_work_time tot_hrs_wk {
areg d`y' dcrop dcrop_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
outreg2 using "$Tablesdir/ch_female_labour_supply_dcrop.log", br keep(dcrop dcrop_treat1) ctitle("d`y'")
areg d`y' dcrop dcrop_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
boottest dcrop
boottest dcrop_treat1

areg d`y' dintensity dintensity_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
outreg2 using "$Tablesdir/ch_female_labour_supply_dcrop.log", br keep(dintensity dintensity_treat1) ctitle("d`y'")
areg d`y' dintensity dintensity_treat1         $regressors1, absorb(vill1) cluster ($ourcluster)
boottest dintensity
boottest dintensity_treat1
}
}


restore




